# File:     JOP_RR1_financial_topics.R
# Purpose:  This script applies Nicolo's financial topics to the data
# Input:    /Data/finalData.RData
# Output:   
# Author:   JB


rm(list = ls())
require(tidyverse)
require(ggridges)
# devtools::install_github('jbisbee1/QualtricsCreatoR')
require(QualtricsCreatoR)

setwd('C:/Users/Jimbo/Dropbox/FED/FED/Paper/JOP/RR1_replication/')

load('./data/finalData.RData')

set.seed(123)
svy <- list()
for(i in 1:99) {
  tmp <- utterance_level %>%
    filter(nchars < 1000,nchars > 200) %>%
    select(textclean,SENT = SENT_combAttack,nchars) %>%
    mutate(SENTHIGH = SENT > .5,
           SENTLOW = SENT < .02) %>%
    filter(SENTHIGH | SENTLOW) %>%
    group_by(SENTHIGH,SENTLOW) %>%
    sample_n(size = 1)
  
  inds <- sample(1:2,2)
  tmp2 <- gsub(' Bernanke| Yellen| Greenspan| Powell| Mr\\.| Ms\\.| Mrs\\.','',tmp$textclean[inds])
  names(tmp2) <- round(tmp$SENT[inds],4)
  svy[[paste0('Q',i,': Which of the following is more aggressive?')]] <- tmp2
  
}
create_survey(question.type = "MC",
              answer.type = "SingleAnswer",
              orientation = "Vertical",
              survey.content = svy,
              matrix.answers = "None",
              n.questions.per.block = 10,
              filename = "MCSurvey.txt")



